﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Battle.Net.Infrastructure;

namespace Battle.Net.Model
{
    [DataContract]
    public class GuildAchievements
    {
        [DataMember(Name = "achievementsCompleted")]
        internal List<int> AchievementsCompleted { get; set; }
        [DataMember(Name = "achievementsCompletedTimestamp")]
        internal List<string> AchievementsCompletedTimestamp { get; set; }
        [DataMember(Name = "criteria")]
        internal List<int> Criteria { get; set; }
        [DataMember(Name = "criteriaCompleted")]
        internal List<string> CriteriaCreated { get; set; }
        [DataMember(Name = "criteriaQuantity")]
        internal List<int> CriteriaQuantity { get; set; }
        [DataMember(Name = "criteriaTimestamp")]
        internal List<string> CriteriaTimestamp { get; set; }


        private List<Achievement> _achievements; 
        public List<Achievement> Achievements
        {
            get
            {
                if (_achievements != null)
                    return _achievements;

                _achievements = new List<Achievement>();
                var acIdx = 0;
                foreach (var ac in AchievementsCompleted)
                {
                    var element = new Achievement
                        {
                            Id = ac,
                            CompletedTimestamp = AchievementsCompletedTimestamp[acIdx].FromUnixTimestamp()
                        };
                    acIdx++;
                    _achievements.Add(element);
                }
                return _achievements;
            }
        }

    }

    [DataContract]
    public class Achievement
    {
        [DataMember(Name = "accountWide")]
        public bool AccountWide { get; set; }
        [DataMember(Name = "criteria")]
        public List<Criteria> Criteria { get; set; }
        [DataMember(Name = "description")]
        public string Description { get; set; }
        [DataMember(Name = "icon")]
        public string Icon { get; set; }
        [DataMember(Name = "id")]
        public int Id { get; set; }
        [DataMember(Name = "points")]
        public int Points { get; set; }
        [DataMember(Name = "reward")]
        public string Reward { get; set; }
        [DataMember(Name = "rewardItems")]
        public List<Item> RewardItems { get; set; }

        public Nullable<DateTime> CompletedTimestamp { get; set; }
    }

    [DataContract]
    public class Criteria
    {
        [DataMember(Name = "description")]
        public string Description { get; set; }
        [DataMember(Name = "id")]
        public int Id { get; set; }
        [DataMember(Name = "max")]
        public int Max { get; set; }
        [DataMember(Name = "orderIndex")]
        public int OrderIndex { get; set; }

        public Nullable<DateTime> StartedTimestamp { get; set; }

        public Nullable<DateTime> CompletedTimestamp { get; set; }


    }
}
